import fs from '../fs/index'
import { fromPromise } from '../../universalify/index'
import { LogUtil } from '../../../LogUtil'

function pathExists (path) {
    try {
        LogUtil.info('pathExists');
        return new Promise((res, rej) => {
            res(fs.access(path).then(() => true).catch(() => false))
        })
    } catch (e) {
        LogUtil.error('pathExists error: %{public}s', e.message);
    }
}

function pathExistsSync(path) {
    try {
        LogUtil.info('pathExists');
        return fs.existsSync(path);
    } catch (e) {
        LogUtil.error('pathExistsSync error: %{public}s', e.message);
    }

}

export default {
    pathExists: fromPromise(pathExists),
    pathExistsSync
}